import React, {Component} from 'react'
import './index.css'

export default class Footer extends Component {

    //全选checkbox的回调
    handleCheckAll = (event) => {
        //根据是否选择返回 true false
        this.props.checkAllTodo(event.target.checked)
    }

    //清除已完成任务的回调
    handleClearAllDone = () => {
        this.props.clearAllDone()
    }

    render() {
        const {todos} = this.props
        //已完成的个数  这么写有点装比的感觉 初始值为0 每次加1
        const doneCount = todos.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0)
        //总数
        const total = todos.length
        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" onChange={this.handleCheckAll}
                           checked={doneCount === total && total !== 0}/>
                </label>
                <span>
					<span>已完成:{doneCount}</span> / 全部:{total}
				</span>
                <button onClick={this.handleClearAllDone} className="btn btn-danger">清除已完成任务</button>
            </div>
        )
    }

}
